<?php

namespace App\Providers;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Validator::extend('mobile', function($attribute, $value, $parameters) {
            $reg = '/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/';
            if (  preg_match($reg, $value)) {
                return true;
            }
            return '请正确填写手机号码';

        });

        Validator::extend('chs', function ($attribute, $value, $parameters, $validator) {
            //UTF-8汉字
            $reg = '/^[\x{4e00}-\x{9fa5}\x{9fa6}-\x{9fef}\x{3400}-\x{4db5}\x{20000}-\x{2ebe0}]+$/u';
            if (  preg_match($reg, $value)) {
                return true;
            }
            return false;
        });

        Validator::extend('chsDash', function ($attribute, $value, $parameters, $validator) {
            //UTF-8汉字字母数字下划线
            $reg = '/^[A-Za-z0-9\-\_]+$/';
            if ( preg_match($reg, $value)) {
                return true;
            }
            return '由汉子字母数字下划线组成';
        });

    }
}
